package com.hsoft.zhxy.app.xtgl_02_01.service.impl;


import com.hsoft.zhxy.app.xtgl_02_01.mapper.JcqxJszyMapper;
import com.hsoft.zhxy.app.common.model.entity.JcqxJszy;
import com.hsoft.zhxy.app.xtgl_02_01.service.JcqxJszyService;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.hsoft.zhxy.common.base.BaseService;
import com.hsoft.zhxy.common.result.ResultBody;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.List;

 /**
 * All rights Reserved, Designed By 哈尔滨工业大学软件工程股份有限公司
 * 
 * @Title: 角色资源 Service层接口实现类
 * @Package 
 * @Description: 
 * @author: system
 * @date: 2020-10-26
 */
@Log4j2
@Service
public class JcqxJszyServiceImpl extends BaseService implements JcqxJszyService {

    @Autowired
    private JcqxJszyMapper jcqxJszyMapper;


    /**
     * 查询单条数据
     * @param jcqxJszy
     * @return
     */
    public JSONObject findOne(JcqxJszy jcqxJszy) {
        JcqxJszy rs = jcqxJszyMapper.selectOne(new QueryWrapper<JcqxJszy>().setEntity(jcqxJszy));
        return ResultBody.setData(rs);
    }


    /**
     * 查询列表数据
     * @param jcqxJszy
     * @return
     */
    public JSONObject findList(JcqxJszy jcqxJszy) {
        List<JcqxJszy> list = jcqxJszyMapper.selectList(new QueryWrapper<JcqxJszy>().setEntity(jcqxJszy));
        return ResultBody.setData(list);
    }


    /**
     * 查询分页数据
     * @param jcqxJszy
     * @param page
     * @param pageSize
     * @return
     */
    public JSONObject findListByPage(JcqxJszy jcqxJszy, long page, long pageSize) {

        Page<JcqxJszy> pageObj = new Page<JcqxJszy>(page, pageSize);
        IPage<JcqxJszy> result = jcqxJszyMapper.selectPage(pageObj, new QueryWrapper<JcqxJszy>().setEntity(jcqxJszy));

        return ResultBody.setData(result.getTotal(), result.getRecords());
    }


    /**
     * 新增
     * @param jcqxJszy
     * @return
     */
    public JSONObject add(JcqxJszy jcqxJszy) {
        jcqxJszy.setCjsj(LocalDateTime.now());
        jcqxJszy.setCjr(getYhid());
        jcqxJszy.setBgsj(LocalDateTime.now());
        jcqxJszy.setBgr(getYhid());
        return ResultBody.setData(jcqxJszyMapper.insert(jcqxJszy));
    }


    /**
     * 修改
     * @param jcqxJszy
     * @return
     */
    public JSONObject update(JcqxJszy jcqxJszy) {
        jcqxJszy.setBgsj(LocalDateTime.now());
        jcqxJszy.setBgr(getYhid());
        return ResultBody.setData(jcqxJszyMapper.updateById(jcqxJszy));
    }


    /**
     * 删除
     * @param jcqxJszy
     * @return
     */
    public JSONObject delete(JcqxJszy jcqxJszy) {
        return ResultBody.setData(jcqxJszyMapper.delete(new QueryWrapper<JcqxJszy>().setEntity(jcqxJszy)));
    }


}
